<template>
  <view>
    <web-view :src="webViewUrl"></web-view>
  </view>
</template>

<script>
var app = getApp()

export default {
  data() {
    return {
      opt: {},
      loading: false,
      webViewUrl: '',
      token: ''
    }
  },
  onLoad: function (options) {
    var token = app.globalData.gtktoken
    this.token = token

    this.setlogin()

    var url = options.url + '?token=' + token
    this.webViewUrl = decodeURIComponent(url)

    if (options.title) {
      uni.setNavigationBarTitle({
        title: options.title
      })
    } else {
      uni.setNavigationBarTitle({
        title: ''
      })
    }
  },
  methods: {
    setlogin() {
      var that = this
      app.post(
        'ApiIndex/logintogether',
        {
          gtksession: that.token
        },
        function (res) {
          if (res.status == 0) {
            //登录过期\或者没有登录
            uni.$u.route({
              type: 'reLaunch',
              url: '/pages/index/login'
            })
          } else {
            that.getdata()
          }
        }
      )
    },
    getdata() {
      var that = this
      that.loading = true
      app.get('ApiMy/usercenter', {}, function (data) {
        that.loading = false

        that.loaded()
      })
    }
  }
}
</script>
